package com.bit.cfdi.web.utils;

import java.util.Random;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

@Repository
public class PasswordGenerator {
	
	protected Logger log = LogManager.getLogger(this.getClass().getName());

	public String generatePassword(int size) {
		char[] chars = new char[size];
		Random randGenerator = new Random();
		
		for(int position=0; position<size; position++) {
			int type = randGenerator.nextInt(3);
			switch(type){
				case(0):{
					chars[position] = getLetter(randGenerator);
				}break;
				case(1):{
					chars[position] = getCapitalLetter(randGenerator);
				}break;
				case(2):{
					chars[position] = getNumberSpecialCharacter(randGenerator);
				}
			}
		}
		
		return new String(chars);
	}
	
	private char getLetter(Random randGenerator) {
		int number = randGenerator.nextInt(25) + 97;
		return (char)number;
	}
	
	private char getCapitalLetter(Random randGenerator) {
		int number = randGenerator.nextInt(25) + 65;
		return (char)number;
	}
	
	private char getNumberSpecialCharacter(Random randGenerator) {
		int number = randGenerator.nextInt(12) + 45;
		return (char)number;
	}
	
//	public static void main(String args[]) {
//		PasswordGenerator password = new PasswordGenerator();
//		System.out.println(password.generatePassword(7));
//	}
}
